#! /usr/bin/env python3
# -*- coding: utf-8 -*-
# :AUTHOR: zb
from flask import (
    render_template,
    request,
    redirect,
    url_for,
    Blueprint,
    abort,
    Response,
    flash,
    Flask,
    current_app
)
import time
from untils.untils import log
from models.cloudoss.nmon import Server


main = Blueprint('nmon', __name__)

servers = [
    ('192.168.240.13','root','Cloud$osshk',22),
    ('192.168.240.13','root','Cloud$osshk',22),
    ('192.168.240.13','root','Cloud$osshk',22),
    ('192.168.240.13','root','Cloud$osshk',22),
]

@main.route("/")
def index():

    return render_template("cloudoss/index.html" )

@main.route("/startAll")
def startAll():
    for s in servers:
        server = Server(s)
        result = server.excute_command('/root/nmon/nmon -s 10 -t 600 -f -m /root/nmon/reuslt')

    return render_template("cloudoss/index.html", result=result)

@main.route("/stopAll")
def stopAll():

    for s in servers:
        server = Server(s)
        result = server.excute_command("ps -ef|grep nmon|awk '{print $2}'| xargs kill -9 ")

    return render_template("cloudoss/index.html", result=result)


@main.route("/downloadAllResult")
def downloadAllResult():
    for s in servers:
        server = Server(s)
        server.download('/root/nmon/result', r'~/')

    return render_template("cloudoss/index.html", result=result)


if __name__ == '__main__':
    pass
